package com.boot.mgt.controller

import com.boot.core.result.ResultEnum
import com.boot.core.result.ResultTo
import com.boot.mgt.service.LoginService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.client.RestTemplate

/**
 * @author rankai
 * createTime 2018-01-2018/1/9 11:09
 */
@RestController
@RequestMapping("/user")
class LoginRpcController {

    @Autowired
    private lateinit var loginService: LoginService

    /**
     * 登陆
     */
    @PostMapping("/login")
    fun login(police_number: String, password: String, login_type: Int?): ResultTo {
        return loginService.login(police_number, password, login_type ?: 2)
    }

    /**
     * 退出
     */
    @PostMapping("/logout")
    fun logout(session_key: String): ResultTo {
        loginService.logout(session_key)
        return ResultTo()
    }

    /**
     * 判断是登陆
     */
    @PostMapping("/isLogin")
    fun logout(): ResultTo {
        return ResultTo(ResultEnum.SUCCESS).setData("ver", "1.0.0")
    }

    /**
     * 统一认证票据验证接口
     * 1.验证结果flag：0验证通过，1票据信息过期，2票据信息验证未通过，3该票据信息不属于平台发放票据，4其它错误。
     */
    @GetMapping("/verifyBillUnify")
    fun verifyBillUnify(strBill: String): Any? {
        val URL = "http:/20.80.4.141:15002/uas/sso/singlesignoncontrol/checkbill.do?strBill="
        var restTemplate = RestTemplate()
        var resultVeriry = restTemplate.getForObject((URL+ strBill), HashMap::class.java)
        return resultVeriry
    }

}
